<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      >
    <h:head>
        <title>Quản lí tài khoản</title>
        <script>
            function confirmComplete() {
                var answer = confirm("Bạn có chắc chắn muốn xóa bản ghi này?");
                if (answer == true)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        </script>        
    </h:head>
    <h:body> 
        <link type="text/css" rel="stylesheet" href="../css/main.css" />        
        <style type="text/css">
            .ui-widget{font-size:95% !important;}
            .ui-layout-unit-content{background-color: #E5E5E5;border-width: 0px}      
            .ui-widget{border-width: 0px;color: red}
        </style>
        <div align="center" id="bodyForm" >            
            <div style="width: 100%;">
                <p:layoutUnit id="top" position="north" size="auto">
                    <ui:insert name="menu">
                        <ui:include src="../../templates/menu.xhtml"/>
                    </ui:insert>
                </p:layoutUnit>

                <p:layoutUnit id="center" position="center" size="400">
                    <h1 class="headerbar">Quản lí tài khoản</h1>
                    <p:commandButton value="Thêm" icon="ui-icon ui-icon-circle-plus" onclick="dlgAdd.show()" update=":formDlgAdd" action="#{iPCC_EXTENSIONSController.prepareInsert()}"/>
                    <h:form id="form">
                        <br></br>
                        <p:growl id="messages"/> 
                        <p:dataTable value="#{iPCC_EXTENSIONSController.lazyIEModel}" var="i" 
                                     paginator="true" paginatorPosition="bottom"
                                     rows="20" rowsPerPageTemplate="20,25,30" lazy="true">
                            <p:column headerText="Extension">
                                <h:outputText value="#{i.extension}" style="float: right"/>
                            </p:column>
                            <p:column headerText="Created date">
                                <h:outputText value="#{i.created_date}" style="float: right"/>
                            </p:column>
                            <p:column headerText="Extension group">
                                <h:outputText value="#{i.ipcc_extension_groups.getNameById()}" style="float: right"/>
                            </p:column>
                            <p:column headerText="Status">
                                <h:outputText value="Ngừng hoạt động" style="float: right" rendered="#{i.status eq 0}"/>
                                <h:outputText value="Chờ duyệt" style="float: right" rendered="#{i.status eq 1}"/>
                                <h:outputText value="Hoạt động" style="float: right" rendered="#{i.status eq 2}"/>
                            </p:column>
                            <p:column headerText="Edit" style="width: 10px">
                                <div align="center">
                                    <p:commandButton style="height: 20px;width: 20px;" styleClass="ui-icon ui-icon-pencil" onclick="dlgUpdate.show()" update=":formDlgUpdate" actionListener="#{iPCC_EXTENSIONSController.prepareEdit(i)}" rendered="#{i.status eq 1}"/>
                                </div>
                            </p:column>
                            <p:column headerText="Edit Password" style="width: 10px">
                                <div align="center">
                                    <p:commandButton style="height: 20px;width: 20px;" styleClass="ui-icon ui-icon-wrench" onclick="dlgChangePwd.show()" update=":formDlgChangePwd" actionListener="#{iPCC_EXTENSIONSController.prepareChangePwd(i)}" rendered="#{i.status eq 2}"/>
                                </div>
                            </p:column>
                            <p:column headerText="Delete" style="width: 10px">                                            
                                <div align="center">
                                    <p:commandButton style="height: 20px;width: 20px;" styleClass="ui-icon ui-icon-trash" onclick="return confirmComplete()" update=":form" action="#{iPCC_EXTENSIONSController.remove(i)}" rendered="#{i.status eq 1}"/>
                                </div>
                            </p:column>
                        </p:dataTable>                        
                    </h:form>
                    <!--dialog add-->
                    <p:dialog widgetVar="dlgAdd" modal="true" resizable="false" header="Thêm tài khoản">
                        <h:form id="formDlgAdd">
                            <p:growl/>
                            <h:panelGrid columns="2">
                                <h:outputText value="Extension: "/><p:inputText value="#{iPCC_EXTENSIONSController.current.extension}"/>
                                <h:outputText value="Extension group: "/>
                                <p:selectOneMenu value="#{iPCC_EXTENSIONSController.current.ipcc_extension_groups.group}">
                                    <f:selectItems value="#{iPCC_EXTENSIONSController.listEG}" var="eg"
                                                   itemLabel="#{eg.group_name}" itemValue="#{eg.group}" />   
                                </p:selectOneMenu>
                                <h:outputText value="Password: "/><p:password id="password" value="#{iPCC_EXTENSIONSController.current.password}" feedback="true" match="pwd2" required="true"/>
                                <h:outputText value="Re-password: "/><p:password id="pwd2" value="#{iPCC_EXTENSIONSController.current.password}" required="true"/>
                            </h:panelGrid>
                            <p:commandButton value="Lưu" action="#{iPCC_EXTENSIONSController.insert()}" update=":formDlgAdd :form" oncomplete="dlgAdd.hide()"/>
                        </h:form>
                    </p:dialog>
                    <!--dialog update-->
                    <p:dialog widgetVar="dlgUpdate" modal="true" resizable="false" header="Sửa tài khoản">
                        <h:form id="formDlgUpdate">
                            <p:growl/>
                            <h:panelGrid columns="2">
                                <h:outputText value="Extension: "/><p:inputText value="#{iPCC_EXTENSIONSController.current.extension}"/>
                                <h:outputText value="Extension group: "/>
                                <p:selectOneMenu value="#{iPCC_EXTENSIONSController.current.ipcc_extension_groups.group}">
                                    <f:selectItems value="#{iPCC_EXTENSIONSController.listEG}" var="eg"
                                                   itemLabel="#{eg.group_name}" itemValue="#{eg.group}" />   
                                </p:selectOneMenu>                            
                            </h:panelGrid>
                            <p:commandButton value="Lưu" action="#{iPCC_EXTENSIONSController.update()}" update=":formDlgUpdate :form" oncomplete="dlgUpdate.hide()"/>
                        </h:form>
                    </p:dialog>
                    <!--dialog Change Pwd-->
                    <p:dialog widgetVar="dlgChangePwd" modal="true" resizable="false" header="Đổi mật khẩu">
                        <h:form id="formDlgChangePwd">
                            <p:growl/>
                            <h:panelGrid columns="2">
                                <h:outputText value="Old Password: "/><p:password required="true" value="#{iPCC_EXTENSIONSController.oldPassword}"/>
                                <h:outputText value="New Password: "/><p:password id="password" value="#{iPCC_EXTENSIONSController.current.password}" feedback="true" match="pwd2" required="true"/>
                                <h:outputText value="Re-password: "/><p:password id="pwd2" value="#{iPCC_EXTENSIONSController.current.password}" required="true"/>
                            </h:panelGrid>
                            <p:commandButton value="Xác nhận" action="#{iPCC_EXTENSIONSController.changePwd()}" update=":formDlgChangePwd" oncomplete="dlgChangePwd.hide()"/>
                        </h:form>
                    </p:dialog>
                </p:layoutUnit>
                <p:layoutUnit id="bottom" position="bottom" size="60">
                    <ui:insert name="footer">
                        <ui:include src="../../templates/footer.xhtml"/>
                    </ui:insert>
                </p:layoutUnit>
            </div>
        </div>
    </h:body>
</html>

